from __future__ import unicode_literals
import requests
from bs4 import BeautifulSoup
import time
import json
baseurl='https://www.youx.xxx'
strat_url='https://www.youx.xxx/tag/asian/video/'

ulist=[]
ulist.append(strat_url)

while len(ulist)>0:
    try:
        n_url=ulist.pop()
        time.sleep(2)
        r=requests.get(n_url,timeout=7)
        content=r.content
        soup=BeautifulSoup(content,'lxml')
        with open('temp.txt','w+',encoding='utf-8') as f:
            f.write(r.text)

        for item in soup.find_all('a',attrs={'class':'np'}):
            if item.text=='Next':
                next_url=baseurl+item['href']
                #print(next_url)
                ulist.append(next_url)
                break
        for item in soup.find_all('img'):
            try:
                mp4url=item['data-src-video']
                #print(mp4url)
                with open('youx.txt','a',encoding='utf-8') as f:
                    f.write(mp4url+'\n')
            except Exception as identifier:
                pass

        
    except Exception as identifier:
        print(identifier)